⚡ Bolt: Add O(1) caching for station lookups#131
⚡ Bolt: Add O(1) caching for station lookups#131OsakaLOOP wants to merge 1 commit intobefore-refractorfrom
Conversation
Replaces inefficient O(N*M) lookups inside `TripsPage.tsx`, `WalkTripEditor.tsx`, and `RailRound.jsx` with an O(1) cache. 💡 What: Implemented a cached Map inside `src/core/railwayRouting.ts` (`stationIdIndexCache`) to index stations by ID. 🎯 Why: Iterating over `Object.values(railwayData)` to find stations by ID caused large temporary allocations and blocked the UI thread, especially when rendering walk trips. 📊 Impact: Reduces time complexity of lookup from O(N * M) to O(1), significantly accelerating render performance for trip pages. 🔬 Measurement: Verified caching correctness and reference-equality invalidation via manual test files, verified components compilation via TS checker. Co-authored-by: OsakaLOOP <68284076+OsakaLOOP@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
⚡ Bolt: Add O(1) caching for station lookups
💡 What:
Implemented a cached
Mapinsidesrc/core/railwayRouting.ts(stationIdIndexCache) to index stations by ID, replacing inefficientObject.values(railwayData)iterations that were heavily used in component rendering loops.🎯 Why:
Iterating over the entire geographical transit dataset (
railwayData) to linearly scan (Array.prototype.find) for a station ID caused large temporary allocations and blocked the main UI thread. This was especially apparent when rendering large lists of "walk trips" insideTripsPage.tsx,WalkTripEditor.tsx, andRailRound.jsx.📊 Impact:$O(N \times M)$ to $O(1)$ . This dramatically accelerates list render performance and saves memory by removing multiple temporary array allocations from
Reduces time complexity of station lookups from
.forEachloops.🔬 Measurement:
stationIdIndexCachecorrectly invalidates automatically by checking object referential equality (lastRailwayDataRef === railwayData), fitting perfectly into the existing global Zustand state immutability.PR created automatically by Jules for task 6504686804854981851 started by @OsakaLOOP